define(function () {
    'use strict';

    function ctrl($scope, $filter,$stateParams,InfoService,CommonService) {

        $scope.channel = {};
        $scope.channel.channelId = $stateParams['id'];
        $scope.vm = {};

        init();

        $scope.doRefresh = function() {
            init();
            $scope.$broadcast('scroll.refreshComplete');

        };

        $scope.loadMore = function() {
            return queryContentBriefs();
        };

        function init(){
            $scope.items = new Array();
            $scope.page_no = 1;
            $scope.vm.loadMore = true;
        }

        function queryContentBriefs(){
            return InfoService.getProductsByChannelId($scope.channel.channelId, $scope.page_no).then(function(data){
                if(data && data.length > 0){
                    for(var i=0;i<data.length;i++){
                        var fund = data[i];
                        fund.prod_min_subscribe = $filter('prodMinSubscribe')(CommonService.getMinAmount(fund));
                    }
                    $scope.items = $scope.items.concat(data);
                    $scope.page_no++;
                } else {
                    $scope.vm.loadMore = false;
                }
                $scope.$broadcast('scroll.infiniteScrollComplete');
            });
        }
    }

    ctrl.$inject = ['$scope','$filter','$stateParams','InfoService','CommonService'];
    return ctrl;
});